package filesLessons;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map.Entry;

public class MyWordCounter {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		try(FileInputStream fis = new FileInputStream("C:\\eclipse\\step\\vimir.txt")){
			try(InputStreamReader isr = new InputStreamReader(fis, "UTF-8")){
				try(BufferedReader br = new BufferedReader(isr)){
					String s;
					HashMap<String,Integer> hm = new HashMap<String,Integer>();
					while(br.ready()){
						s = br.readLine();
						String[] words = s.split("[\\p{Punct}\\s]");
						for(String word:words){
							if(hm.containsKey(word)){
								hm.put(word, hm.get(word)+1);
							}else{
								hm.put(word,1);
							}
						}
					}
					
					for(Entry<String,Integer> e:hm.entrySet()){
						System.out.println(e.getKey()+" "+e.getValue());
					}
				}
			}
			
		}
		catch (IOException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}

	}

}
